package com.jilujia.domain.user;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

import com.jilujia.framework.domain.PoEntity;

/**
 * A user who can book hotels.
 */
@Entity
@Table(name = "TB_USER")
public class User implements PoEntity<Long>, Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3652559447682574722L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@Email
	@NotEmpty
	private String username;

	@NotEmpty
	private String password;

	@Transient
	private String password2;

	@NotEmpty
	private String nickname;

	private String kaptcha;

	private boolean active = false;

	private boolean enable = false;

	private String confirmtoken;

	private Integer version;

	public User() {
	}

	public User(String username, String password, String nickname) {
		this.username = username;
		this.password = password;
		this.nickname = nickname;
	}

	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	@Override
	public String toString() {
		return "User(" + username + ")";
	}

	@Version
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public boolean getActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public boolean getEnable() {
		return enable;
	}

	public void setEnable(boolean enable) {
		this.enable = enable;
	}

	public String getConfirmtoken() {
		return confirmtoken;
	}

	public void setConfirmtoken(String confirmtoken) {
		this.confirmtoken = confirmtoken;
	}

	public String getPassword2() {
		return password2;
	}

	public void setPassword2(String password2) {
		this.password2 = password2;
	}

	@Transient
	public String getKaptcha() {
		return kaptcha;
	}

	public void setKaptcha(String kaptcha) {
		this.kaptcha = kaptcha;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof User) {
			if (this.getId() == null) {
				return this.getId() == ((User) obj).getId();
			} else {
				return this.getId().longValue() == ((User) obj).getId().longValue();
			}
		}
		return false;
	}

}
